In [ ]:
a = 17
b = 23

a == b

In [ ]:
a > b

In [ ]:
a < b

In [ ]:
b = 17

a == b

In [ ]:
a > b

In [ ]:
a >= b

In [ ]:
c = 'cat'
d = 'dog'

c == d

In [ ]:
c != d

In [ ]:
print(a,b)

In [ ]:
a = 40
b = 27
c = 0

if a == b:
    print("a equals b!  hooray!")
    c = 1
    
if a < b:
    print("a less than b")
    c = 2
    
if a > b:
    print("a greater than b")
    c = 3

print("the value of c is:", c)

In [ ]:
a = 30
b = 17

if a > b:
    print("a greater than b")
    
    if a <= 25:
        print("a is less than or equal to 25")

    if a > 25:
        print("a is huge.")

a = 51 b = 15 c = 10

if (a < 50 or b > 10) or c > 10: print("lots of things are true!")

what have we learned?

  • Boolean logic tells us if expressions are true or false
  • We use the 'if' statement to evaluate expressions and act on that.
  • We can combine multiple expressions together in an if statement to make very complex comparisons and decisions